﻿using System;
using DirectoryViewModels;
using System.Collections.ObjectModel;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC.FolderExplorer
{
    public class FolderOperations : ObservableCollection<FolderOperation>
    {
        public ThreadSafeListAndLookup<string, FolderOperation> OperationLookup = new ThreadSafeListAndLookup<string, FolderOperation>();

        public void AddOperation(FolderOperation op, FolderViewModel folder)
        {
            if (OperationLookup.Add(op.Name, op))
            {
                this.Add(op);

                if (folder != null)
                {
                    folder.RaiseCurrentWorkChanged();
                }
            }
        }

        public void RemoveOperation(string name, FolderViewModel folder)
        {
            FolderOperation op = OperationLookup.Remove(name, o => o.Name == name);
            if (op != null)
            {
                this.Remove(op);

                if (folder != null)
                {
                    folder.RaiseCurrentWorkChanged();
                }
            }
        }

        public bool HasOperation(string name)
        {
            return OperationLookup[name].Count > 0;
        }
    }
}
